#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 2e5+10;
const int maxm = 450+10;
int mod = 998244353;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
int n,m;
const int T = 450;
int f[maxm][maxn];
void inc(int &x,int y) {
	x += y-mod; x += ((x>>31)&mod);
}
void Solve() {
	cin >> n;
	int ret = 0;
	for(int i = 1; i*i <= n; i++) if(!((n-i*i)&1)) {
//		cerr<<i<<' '<<f[i][(n-i*i)/2]<<'\n';
		inc(ret,f[i][(n-i*i)/2]);
	}
	cout<<ret<<'\n';
}
int main() {
	freopen("moon.in","r",stdin);
	freopen("moon.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int TT; cin >> TT >> mod; 
	f[0][0] = 1;
	const int M = 2e5;
	for(int i = 1; i <= T; i++) {
		for(int j = 0; j <= M; j++) {
			f[i][j] = f[i-1][j];
		}
		for(int j = i; j <= M; j++) {
			inc(f[i][j],f[i][j-i]);
		}
	}
	while(TT--) Solve();
	return 0;
}
